using System;
using System.Collections.Generic;
using System.Text;
using Ghasam.Business.Domain.Entity;
using NHibernate;
using NHibernate.Expression;

namespace Ghasam.Business.DAO.Impl
{
    public class StockDao :DaoBase<Stock>,IStockDao
    {
        public IList<Stock> FindStock(string name, string binnumber, string serial, int? status, DateTime? importdate, int pageSize, int pageNo)
        {
             ICriteria cri = base.Session.CreateCriteria(typeof(Stock));
             if (name.Length > 0)
             {
                 cri.Add(Expression.Like("StockName", name, MatchMode.Anywhere));
             }

             if (binnumber.Length > 0)
             {
                 cri.Add(Expression.Like("BinNumber", binnumber, MatchMode.Anywhere));
             }

             if (serial.Length > 0)
             {
                 cri.Add(Expression.Eq("Serial", serial));
             }

             if (status.HasValue && status > 0)
             {
                 cri.Add(Expression.Eq("StockStatus.Id", status.Value));
             }

             if (importdate.HasValue)
             {
                 cri.Add(Expression.Eq("ImportDate", importdate.Value));
             }


           //cri.SetMaxResults(pageSize * pageNo);
            //cri.SetFirstResult(pageSize * pageNo);
            return cri.List<Stock>();
        }
        public IList<Stock> FindOrderPoint()
        {
            return HibernateTemplate.Find<Stock>("from Stock as stock where stock.OrderPoint > stock.Quantity");
        }
    }
}
